package com.sky.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.context.BaseContext;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Employee;
import com.sky.mapper.CategoryMapper;
import com.sky.result.PageResult;
import com.sky.service.CategoryService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public void addCategory(CategoryDTO category1) {
        Category category = new Category();
        BeanUtils.copyProperties(category1,category);
        category.setStatus(0);//默认禁用
        categoryMapper.addNewCategory(category);
    }

    public PageResult getAllCategory(CategoryPageQueryDTO categoryPageQueryDTO){
        PageHelper.startPage(categoryPageQueryDTO.getPage(), categoryPageQueryDTO.getPageSize());
        Page<Category> pg = categoryMapper.pageQuery(categoryPageQueryDTO);
        return new PageResult( pg.getTotal(), pg.getResult());

    }

    public void delete(Integer id){
        categoryMapper.delete(id);
    }

    public void update(Long id, Integer status){
        Category category = new Category();
        category.setId(id);
        category.setStatus(status);

        categoryMapper.update(category);
    }

    public void updateClass(CategoryDTO category){
        Category category1 = new Category();
        BeanUtils.copyProperties(category,category1);
        categoryMapper.update(category1);
    }

    public List<Category> getCategroyByClass(Integer type){
        return categoryMapper.getCategoryByClass(type);
    }



}
